package com.ruoyi.web.controller.warning;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.warning.domain.entity.DrawingBoardDevicexy;
import com.ruoyi.warning.service.IDrawingBoardDevicexyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-04-27
 */
@RestController
@RequestMapping("/drawingBoardDevicexy")
@Api(tags = "画板位置", description = "用于处理画板位置相关操作的控制器")
public class DrawingBoardDevicexyController {
@Resource
private IDrawingBoardDevicexyService drawingBoardDevicexyService;

    @ApiOperation("重置画板的XY坐标")
    @PostMapping(value = "/resetXY")
    public R resetXY(@RequestBody List<Integer> list)
    {
        return R.ok(drawingBoardDevicexyService.resetXY(list));
    }

    @ApiOperation("获取画板拓扑结构")
    @GetMapping(value = "/getDrawingBoardTopology/{id}")
    public R getDrawingBoardTopology(@PathVariable Integer id)
    {
        return R.ok(drawingBoardDevicexyService.getDrawingBoardTopology(id));
    }

    @ApiOperation("新增或更新画板拓扑结构")
    @PostMapping(value = "/saveOrUpdateTopology")
    public R saveOrUpdateTopology(@RequestBody List<DrawingBoardDevicexy> list)
    {
        LambdaQueryWrapper wrapper = new QueryWrapper<DrawingBoardDevicexy>().lambda()
                .eq(DrawingBoardDevicexy::getBroadId, list.get(0).getBroadId());
        List<DrawingBoardDevicexy> devicexyList = drawingBoardDevicexyService.list(wrapper);
        List<Integer> idList = devicexyList.stream().map(DrawingBoardDevicexy::getId).toList();
        drawingBoardDevicexyService.removeByIds(idList);
        return R.ok(drawingBoardDevicexyService.saveBatch(list));
    }


}
